<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>地址管理</title>
		<meta http-equiv="pragma" content="no-cache"> 
	    <meta http-equiv="Cache-Control" content="no-cache, must-revalidate"> 
	    <meta http-equiv="expires" content="0">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
		<link rel="stylesheet" href="../css/mui.min.css" />
		<link rel="stylesheet" href="../css/common.css" />
		
	</head>
	<style type="text/css">
		* {
			margin: 0;
			padding: 0;
		}
		body {
			background: #F3F3F3;
			width: 100%;
			height: 100%;
		}
		.mui-content {
			width: 100%;
			height: 100%;
			background-color: #F3F3F3;
		    -webkit-overflow-scrolling: touch;
		}
		.header-div {
			margin: 2px;
			padding: 10px;
		}
		.footer-div {
			height: 55px;
			position: absolute;
			left: 0;
			right: 0;
			bottom: 0px;
			background: #FFFFFF;
		}
		.name {
			font-size: 15px;
			color: #515151;
			padding-top: 15px;	
			padding-left: 15px;
			font-family: PingFang-SC-Regular;
		}
		.adress {
			font-size: 12px;
			color: #787878;
			padding: 15px;
			text-align: end;
			font-family: PingFang-SC-Regular;
		}
		.adress-bg {
			background: #FFFFFF;
			margin-top: 3px;
		}
		.img-div {
		}
		.img {
			width: 25px;
			height: 25px;
			margin: 15px;
			border-radius:50% ;
		}
		.editor-img {
			width: 25px;
			height: 25px;
			margin: 15px;
			border-radius:50% ;
		}
		.delete-img {
			width: 25px;
			height: 25px;
			margin: 15px;
			border-radius:50% ;
		}
		.hide {
			display: none;
		}
		.account {
			float: right;
			display: inline-block;
		}
		input[type="radio"]{-webkit-appearance:none;outline: none;border-width: 0px;}
		input.check{background:url(../img/goods/select_norm_icon.png) no-repeat center left;background-size:20px 20px;position:absolute;top:50%;left:10px;margin-top:-18px;width:35px;height:35px;}
		input.check:checked{background:url(../img/goods/selected_icon.png) no-repeat center left;background-size:20px 20px;}
		/*input.goodsCheck:checked{background:url(../img/goods/selected_icon.png) no-repeat center left;background-size:20px 20px;}*/
		/*input.check:checked{background:url(../img/goods/selected_icon.png) no-repeat center left;background-size:20px 20px;}*/
		/*.checked{background:url(../img/goods/selected_icon.png) no-repeat left center;background-size:20px 20px;position:absolute;top:50%;left:15px;margin-top:-18px;width:35px;height:35px;}*/
		.radio-item label {
			margin-left: 20px;
			font-size: 13px;
			color: #4A4A4A;
			letter-spacing: 0.59px;
		}
		.radio-item {
		    padding: 15px;
			display: inline-block;
			position: relative;
		}
		#adressList {
			margin-bottom: 50px;
		}
		.adress-tips-div {
			display: none;
			font-size: 14px;
			color: #e38028;
			text-align: center;
		}
	</style>
	<body class="mui-content">
		<div id="adressList"></div>
		<div class="adress-tips-div">还没有地址哦，点击底部添加地址吧。。。</div>
		<div class="bottom-div">
			<div class="back-div"><a class="mui-action-back"><img style="width: 10px; margin-top: 15px;" src="../img/common/back_icon.png" /></a></div>
			<div class="event-div">新增收货地址</div>
		</div>
	<script type="text/javascript" src="../js/thirdparty/mui.min.js" ></script>
	<script type="text/javascript" src="../js/thirdparty/jquery-3.3.1.js" ></script>
	<script type="text/javascript" src="../js/thirdparty/spin.min.js" ></script>
	<script type="text/javascript" src="../js/utils/boot.js" ></script>
	<script type="text/javascript">
		var userID = base.getParameter("userID");
		$(function() {
			iosPageRefresh(); 
			base.setWait('正在获取数据...');
			var url = base.url.getAddressList;
			var data = {
				userID: userID
			}
			base.postData(url,data,getAddressListSuccess);
		})
		function getAddressListSuccess(data) {
			base.clearWait();
			if (data.success) {
				var tempAddressList = data.context.addressList;
				var html = "";
				for (var index in tempAddressList) {
					html += getArrayListItem(tempAddressList[index],index);
				}
				$("#adressList").html(html);
				if (tempAddressList.length == 0) {
					$(".adress-tips-div").show();
				}
			} else {
				mui.toast(data.msg);
			}
		}
		function getArrayListItem (item,index) {
			var html = "";
			html += '<div class="adress-bg" data-index="' + index + '">'
			html += '	<div class="header-div">'
			html += '		<span class="addressID hide">'+item.addressID+'</span>'
			html += '		<span class="name">'+item.consigneeName+'</span>'
			html += '		<span class="adress">'+item.consigneePhone+'</span>'
			html += '	</div>'
			html += '	<span class="adress">'+item.completeAddress+'</span>'
			html += '	<div>'
			html += '		<div class="radio-item">'
			if (item.isDefaultAddress == 1) {
				html += '			<input type="radio" name="addr" class="check"  checked="checked" >'
			} else {
				html += '			<input type="radio" name="addr" class="check" >'
			}
			html += '			<label for="radioInput3">设为默认地址</label>'
			html += '		</div>'
			html += '		<div class="account">'
			html += '			<img class="editor-img" onclick="" src="'+'../img/address/editor.png'+'"/>'
			html += '			<img class="delete-img" onclick="" src="'+'../img/address/delete.png'+'"/>'
			html += '		</div>'
			html += '	</div>'
			html += '</div>'
			return html;
		}											
		$(".bottom-div").on("tap", ".event-div", function() {
			window.location.href = "newAddress.html?addressID="+"&userID="+userID;
		})
		$("#adressList").on("tap", ".editor-img", function() {
			var addressID = $(this).closest(".adress-bg").find(".addressID").text();
			window.location.href = "newAddress.html?addressID="+addressID+"&userID="+userID;
		})
		$("#adressList").on("tap", ".delete-img", function() {
			var addressID = $(this).closest(".adress-bg").find(".addressID").text();
			base.setWait('正在删除地址...');
			var url = base.url.delAddress;
			var data = {
				userID: userID,
				addressID: addressID
			}
			base.postData(url,data, delAddressDataSuccess.bind(null, $(this)));
		})
		function delAddressDataSuccess(elementID, data) {
			base.clearWait();
			if (data.success) {
				elementID.parent().parent().parent("div").remove();
				mui.toast(data.msg);
			} else {
				mui.toast(data.msg);
			}
		}
		$("#adressList").on("tap", ".radio-item", function() {
			var addressID = $(this).closest(".adress-bg").find(".addressID").text();
			base.setWait('正在设置为默认地址...');
			var url = base.url.setDefaultAddress;
			var data = {
				userID: userID,
				addressID: addressID
			}
			base.postData(url,data,function(data) {
				base.clearWait();
				mui.toast(data.msg);
				setTimeout(function() {
					mui.back();
				}, 1000)
			});
		})
		function iosPageRefresh () { //ios页面返回当前页时强制刷新
			var isPageHide = false;   
			window.addEventListener('pageshow', function () {      
			    if (isPageHide) {        
			      window.location.reload();      
			    }    
			});    
			window.addEventListener('pagehide', function () {
			    isPageHide = true;    
			});
		}
	</script>
	</body>
</html>
